package com.zhentao.websocket.pojo;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.time.LocalDateTime;

/**
 * 群聊消息实体类
 * 存储在 chat_group_message MongoDB 集合中
 */
@Document(collection = "chat_group_message")
public class ChatGroupMessage {
    @Id
    private String id;
    
    @Indexed
    private Long groupId; // 群组ID，关联 ChatGroup
    
    @Indexed
    private String fromName; // 发送者用户名

    @Indexed
    private Integer fromId; // 发送者用户ID

    private String message; // 消息内容
    
    @Indexed
    private LocalDateTime timestamp; // 发送时间
    
    private String messageType = "text"; // 消息类型：text, image, voice, video, file

    // 图片消息相关字段
    private String imageUrl; // 图片URL（当messageType为image时使用）
    private String thumbnailUrl; // 缩略图URL（可选）
    private Long fileSize; // 文件大小（字节）
    private String originalFilename; // 原始文件名

    // 视频消息相关字段
    private String videoUrl; // 视频URL（当messageType为video时使用）
    private String videoCoverUrl; // 视频封面图URL
    private Long videoDuration; // 视频时长（秒）
    private Integer videoWidth; // 视频宽度
    private Integer videoHeight; // 视频高度

    private boolean isDeleted = false; // 是否已删除
    
    // 构造函数
    public ChatGroupMessage() {
    }
    
    public ChatGroupMessage(Long groupId, String fromName, String message) {
        this.groupId = groupId;
        this.fromName = fromName;
        this.message = message;
        this.timestamp = LocalDateTime.now();
    }
    
    public ChatGroupMessage(Long groupId, String fromName, String message, String messageType) {
        this.groupId = groupId;
        this.fromName = fromName;
        this.message = message;
        this.messageType = messageType;
        this.timestamp = LocalDateTime.now();
    }

    // 图片消息专用构造函数
    public ChatGroupMessage(Long groupId, String fromName, String imageUrl, String originalFilename, Long fileSize) {
        this.groupId = groupId;
        this.fromName = fromName;
        this.message = imageUrl; // 图片消息的message字段存储图片URL
        this.messageType = "image";
        this.imageUrl = imageUrl;
        this.originalFilename = originalFilename;
        this.fileSize = fileSize;
        this.timestamp = LocalDateTime.now();
    }

    // 视频消息专用构造函数
    public ChatGroupMessage(Long groupId, String fromName, String videoUrl, String originalFilename, Long fileSize, Long videoDuration) {
        this.groupId = groupId;
        this.fromName = fromName;
        this.message = videoUrl; // 视频消息的message字段存储视频URL
        this.messageType = "video";
        this.videoUrl = videoUrl;
        this.originalFilename = originalFilename;
        this.fileSize = fileSize;
        this.videoDuration = videoDuration;
        this.timestamp = LocalDateTime.now();
    }

    // Getters and Setters
    public String getId() {
        return id;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    public Long getGroupId() {
        return groupId;
    }
    
    public void setGroupId(Long groupId) {
        this.groupId = groupId;
    }
    
    public String getFromName() {
        return fromName;
    }
    
    public void setFromName(String fromName) {
        this.fromName = fromName;
    }

    public Integer getFromId() {
        return fromId;
    }

    public void setFromId(Integer fromId) {
        this.fromId = fromId;
    }

    public String getMessage() {
        return message;
    }
    
    public void setMessage(String message) {
        this.message = message;
    }
    
    public LocalDateTime getTimestamp() {
        return timestamp;
    }
    
    public void setTimestamp(LocalDateTime timestamp) {
        this.timestamp = timestamp;
    }
    
    public String getMessageType() {
        return messageType;
    }
    
    public void setMessageType(String messageType) {
        this.messageType = messageType;
    }
    
    public boolean isDeleted() {
        return isDeleted;
    }
    
    public void setDeleted(boolean deleted) {
        isDeleted = deleted;
    }

    // 图片消息相关的getter和setter
    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public Long getFileSize() {
        return fileSize;
    }

    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }

    public String getOriginalFilename() {
        return originalFilename;
    }

    public void setOriginalFilename(String originalFilename) {
        this.originalFilename = originalFilename;
    }

    public String getThumbnailUrl() {
        return thumbnailUrl;
    }

    public void setThumbnailUrl(String thumbnailUrl) {
        this.thumbnailUrl = thumbnailUrl;
    }

    // 视频相关字段的getter和setter
    public String getVideoUrl() {
        return videoUrl;
    }

    public void setVideoUrl(String videoUrl) {
        this.videoUrl = videoUrl;
    }

    public String getVideoCoverUrl() {
        return videoCoverUrl;
    }

    public void setVideoCoverUrl(String videoCoverUrl) {
        this.videoCoverUrl = videoCoverUrl;
    }

    public Long getVideoDuration() {
        return videoDuration;
    }

    public void setVideoDuration(Long videoDuration) {
        this.videoDuration = videoDuration;
    }

    public Integer getVideoWidth() {
        return videoWidth;
    }

    public void setVideoWidth(Integer videoWidth) {
        this.videoWidth = videoWidth;
    }

    public Integer getVideoHeight() {
        return videoHeight;
    }

    public void setVideoHeight(Integer videoHeight) {
        this.videoHeight = videoHeight;
    }

    @Override
    public String toString() {
        return "ChatGroupMessage{" +
                "id='" + id + '\'' +
                ", groupId=" + groupId +
                ", fromName='" + fromName + '\'' +
                ", fromId=" + fromId +
                ", message='" + message + '\'' +
                ", timestamp=" + timestamp +
                ", messageType='" + messageType + '\'' +
                ", imageUrl='" + imageUrl + '\'' +
                ", thumbnailUrl='" + thumbnailUrl + '\'' +
                ", fileSize=" + fileSize +
                ", originalFilename='" + originalFilename + '\'' +
                ", videoUrl='" + videoUrl + '\'' +
                ", videoCoverUrl='" + videoCoverUrl + '\'' +
                ", videoDuration=" + videoDuration +
                ", videoWidth=" + videoWidth +
                ", videoHeight=" + videoHeight +
                ", isDeleted=" + isDeleted +
                '}';
    }
}
